/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package biofilter.records.NimbleGen;
import biofilter.util.StringUtil;

import biofilter.records.*;
import biofilter.util.*;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Daniel Quest
 */
public class NimbleGenSeqRecord implements Record {

    static StringUtil su = new StringUtil();
    private String probeSequence = "";
    private String probeID = "";
    private String seqID = "";
    private int position = -1;
    private String designNote = "";
    private String selectionCriteria = "";
    private String probeClass = "";
    private double probeTM = Double.MIN_VALUE;
    private double frequency = Double.MIN_VALUE;
    private double rules = Double.MIN_VALUE;
    private double score = Double.MIN_VALUE;
    private int rank = Integer.MIN_VALUE;
    private String record = null;
    public String get(){ return record; }
    public void set(String s){ this.record = s; } 

    public NimbleGenSeqRecord(){

    }

    /**
     * A NimbleGenTiling .seq file looks something like:
     * PROBE_SEQUENCE	                                                PROBE_ID	        SEQ_ID	               POSITION	DESIGN_NOTE	SELECTION_CRITERIA	                                                        PROBE_CLASS	PROBE_TM   FREQUENCY  RULES	SCORE	RANK
     * TCCCGCCTAAAGCCGTAAATGCAGCGCAAATTGGTTGATATGTATAGGAAAAAATTA	CP000568FS000000005	CP000568:1-3843301	5	interval rank	target_tm:76.00;probe_tm:75.20;freq: 1.00;count:01;rules:-300;score:0686	experimental	75.2       1.00       -300	686	1
     * ...
     */

    public boolean parse() {
        String line = this.record;
        String cols[] = null;
        try {
            cols = su.splitOnTab(line, 12);
        } catch (ParseException ex) {
            Logger.getLogger(NimbleGenSeqRecord.class.getName()).log(Level.SEVERE, line, ex);
            return false;
        }

        //ArrayUtil au = new ArrayUtil();
        //au.printArray(cols);
        Double dd = new Double("0");
        Integer ll = new Integer("1");
        probeSequence = cols[0];
        probeID = cols[1];
        seqID = cols[2];
        position = ll.parseInt(cols[3]);
        designNote = cols[4];
        selectionCriteria = cols[5];
        probeClass = cols[6];
        probeTM = dd.parseDouble(cols[7]);
        frequency = dd.parseDouble(cols[8]);
        rules = dd.parseDouble(cols[9]);
        score = dd.parseDouble(cols[10]);
        rank = ll.parseInt(cols[11]);
        return true;
    }
    
    public String getDesignNote() {
        if (this.designNote.equals("")) parse();
        return designNote;
    }

    public void setDesignNote(String designNote) {
        this.designNote = designNote;
    }

    public double getFrequency() {
        if (this.frequency == Double.MIN_VALUE) parse();
        return frequency;
    }

    public void setFrequency(double frequency) {
        this.frequency = frequency;
    }

    public int getPosition() {
        if (this.position == -1) parse();
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public String getProbeClass() {
        if (this.probeClass.equalsIgnoreCase("")) parse();
        return probeClass;
    }

    public void setProbeClass(String probeClass) {
        this.probeClass = probeClass;
    }

    public String getProbeID() {
        if (this.probeID.equals("") ) parse();
        return probeID;
    }

    public void setProbeID(String probeID) {
        this.probeID = probeID;
    }

    public String getProbeSequence() {
        if (this.probeSequence.equals("") ) parse();
        return probeSequence;
    }

    public void setProbeSequence(String probeSequence) {
        this.probeSequence = probeSequence;
    }

    public double getProbeTM() {
        if (this.probeID.equals("")) parse();
        return probeTM;
    }

    public void setProbeTM(double probeTM) {
        this.probeTM = probeTM;
    }

    public int getRank() {
        if (this.rank == Integer.MIN_VALUE) parse();
        return rank;
    }

    public void setRank(int rank) {
        this.rank = rank;
    }

    public double getRules() {
        if (this.rules == Double.MIN_VALUE) parse();
        return rules;
    }

    public void setRules(int rules) {
        this.rules = rules;
    }

    public double getScore() {
        if (this.score == Double.MIN_VALUE) parse();
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    public String getSelectionCriteria() {
        if (this.selectionCriteria.equals("")) parse();
        return selectionCriteria;
    }

    public void setSelectionCriteria(String selectionCriteria) {
        this.selectionCriteria = selectionCriteria;
    }

    public String getSeqID() {
        if (this.seqID.equals("")) parse();
        return seqID;
    }

    public void setSeqID(String seqID) {
        this.seqID = seqID;
    }

}
